package patterns.chain;

/**
 * Created by lenovo on 2016/11/29 0029.
 * 创建一个抽象的总类，日志类，不同的日志级别
 */
public abstract class AbstractLogger {
    public static int INFO = 1;
    public static int FILE = 2;
    public static int ERROR = 3;

    protected int level;

    //责任链中的下一个元素
    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger){
        this.nextLogger = nextLogger;
    }
    public void logMsg(int level, String msg){
        if (this.level<=level){
            write(msg);
        }
        //若是等级级别高于自身，交由更高级别的来处理。
        if (nextLogger !=null){
            nextLogger.logMsg(level,msg);
        }
    }
    //抽象的write方法，用于子类的实现。
    protected abstract void write(String msg);
}
